package com.coder.code.demo

import android.content.ComponentName
import android.content.pm.PackageManager
import android.os.Bundle
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import com.coder.code.R


class LaunchIconUpdateActivity : AppCompatActivity() {

    private val mComponentNameDefault by lazy {
        ComponentName(baseContext,"com.coder.code.icon_normal")
    }
    private val mComponentNameFestival by lazy {
        ComponentName(baseContext,"com.coder.code.icon_festival")
    }


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_launch_icon_update)
    }

    fun onButtonClick(v: View) {
        when (v.id) {
            R.id.btn_update_icon -> {
                enableComponent(mComponentNameFestival)
                disableComponent(mComponentNameDefault)
            }
            R.id.btn_reset_icon -> {
                enableComponent(mComponentNameDefault)
                disableComponent(mComponentNameFestival)
            }
        }
    }

    private fun enableComponent(componentName: ComponentName) {
        packageManager.setComponentEnabledSetting(componentName,
                PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
                PackageManager.DONT_KILL_APP)
    }

    private fun disableComponent(componentName: ComponentName) {
        packageManager.setComponentEnabledSetting(componentName,
                PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
                PackageManager.DONT_KILL_APP)
    }
}